Hello and welcome to the part two of creatine javascript logic for our countdown timer.
Let's begin by creating some variables that we will use for the time calculations.
For days the hours the minutes and the seconds so I will start by creating a variable for the d d we
are counting down.
So here I've added a line of code here.
Line 7 created a variable called D set that to cause the mass stop flow method.
Inside the opponent this is for the emitter.
We passed a part in this variable here called distancing here and dividing by value imperent is these
time you have values in parentheses the values inside the parentheses are calculated first before this.
For example harby doing a thousand times 60 times 60 times 24 then whatever values we hear will be divided
by distance.
Okay so this is a value of distance would divide that by value that we'll get from this calculation.
So this will give us the what is left to the come down in D next to the can down in hours.
I've created another variable online it called ours has set that to the mass floor method.
Again I'm using the distance variable which is is variable.
Here we use them.
The percent sign here.
So again we calculate the values in parenthesis first so we do in this thousand times 60 times 60 times
24 divided by what we get from the result of this calculation.
Which you said a thousand times 60 times 60.
And here we're using the model or symbol model.
Physically is used to find out me remenda.
When you divide values together in modules we will give you what is left and what advice left were going
to use in masto flawed method to around that number and that will give us the hours we have left to
our count down to.
Next I am going to do the same thing here for the minutes so we can find out how Minutes how many minutes
we have left to our countdown date online 9 here.
Added a variable for limits.
He again said that to the amount of floor and inside the is we've got the distance again.
We are multiplying thousand times Sixty 60.
Divide by thousands and 16.
And once we get the values we are using the model of symbiont the model basically will give us a remender
that will give us the minutes left.
Next we want to do three seconds left line 10.
Here we go variable 4 seconds set it to the mass of floor 8 game.
Were you referencing the distance variable we use in the more deloss and we are multiplying a thousand
by 60.
Dividing by a thousand.
And then we use to model loss where the mass of floor rounded up.
Next thing one to do we want to output the result inside our hastier mouth so this is our terminal here
and inside this paragraph.
This T attribute of root.
This is where we are going to inject the conduct time so come down time I will take kofar this right
here and inject the count down here.
So here is where we are going to put.
So we are going to use the documentor get element by D.
So line 12 and 13.
Basically this is what will output the countdown timer.
It outputted inside the room.
This route here is this paragraph here.
Skinner inject it in there so well will the documents kept.
Remember this is a javascript method and the idea we are talking about is this idea called Root which
is a similar document how we use the inner hastier mail.
Basically what that means it will replace whatever value we have inside this route.
Using it in a hasty amount it will replace that with Days.
It is this variable and this is a child form it all.
I prefer it to be ours which is hey minute second.
So to inject whatever value we have from doing this calculations here or inject that inside this idea
which is the idea attribute of roots so to take over this idea here and inject the come down time out
there the next thing I want to do is implement a conditional statement.
Basically what that will do is tool find a way to stop the countdown time the way we have counted down
to details.
For example when we reach January 1st 2010 this time we want the countdown time to stop.
So to do that I'm going to implement a conditional statement.
So I've added the conditional statement which is this block of code here.
So basically I'm saying if the distance which is the distance variable distance variable is less than
zero and then I'm in the clear interval the Clinton method basically is used to clear a timer so close
in time that you set is in this set into a bar method.
I do value that is returned by this integral method is used as the parameter for the clear interval
method.
Also the key thing to note is that to be able to use the collection of a method you must use a global
variable and create in the interval method.
So here the value x we pass in here is value here which is the name for this value for the set interval
method.
Here we are used in the document or get limited by the which is the name is right.
We are replacing the message here with this innate amount of time expired.
So when that value this distance becomes less than zero.
Then we have reached our countdown date and then the condition will no longer be valid.
It would then call they sicklier into a method using this X here which is this said the interval.
It will then display this method the same time expire.
What we're going to do we're more so going to call the interval here.
So just allow us calibrate his thumb to come up hard typing 1000 or so to 1000.
Basically we represent 1 second which is a mini second 1000 milliseconds represents one second.
So the logic is basically complete.
We should be able to get the time I work in now.
So if we just open up your project and just run the count down to the e-mail file.
Thus my time here says I've got 59 days 20 hours 24 minutes 5 seconds left to my countdown date which
is January 1st 2018 24 clock.
So that's my come down.
Next lecture I'm just going to do a bit of csx to make these fonts or the text size a bit bigger.
And I'm also going to give it a background colour or make this black and make the text white so will
do that in the next lecture.
Thanks for watching.
Bye for now.